import random
import time

import openpyxl
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

wb = openpyxl.Workbook()
ws = wb.create_sheet('sheet1')

# 选择浏览器
browser = webdriver.Chrome()
# 访问facebook网页
browser.get('https://www.facebook.com/login.php?login_attempt=1&lwv=110/')
browser.maximize_window()
# 输入账户密码
browser.find_element_by_id('email').clear()
browser.find_element_by_id('email').send_keys('jim_clear@163.com')
browser.find_element_by_id('pass').clear()
browser.find_element_by_id('pass').send_keys('jimclear')
# 模拟点击登录按钮，两种不同的点击方法。。。
try:
    browser.find_element_by_xpath('//button[@id="loginbutton"]').send_keys(Keys.ENTER)
except:
    browser.find_element_by_xpath('//input[@tabindex="4"]').send_keys(Keys.ENTER)
    browser.find_element_by_xpath('//a[@href="https://www.facebook.com/?ref=logo"]').send_keys(Keys.ENTER)
# result = EC.alert_is_present()(browser)  # 检测是否有弹窗
# if result:  # 当有弹窗时
#     al = browser.switch_to_alert()  # 获取弹窗的位置
#     time.sleep(random.random() * 10)
#     al.accept()
time.sleep(10)
browser.find_element_by_xpath("//ul[@class='thodolrn ojvp67qx taijpn5t buofh1pr j83agx80 aovydwv3 bqdfd6uv']/li[@class='buofh1pr to382e16 o5zgeu5y jrc8bbd0 dawyy4b1 h676nmdw hw7htvoc'][2]/span[@class='tojvnm2t a6sixzi8 abs2jz4q a8s20v7p t1p8iaqh k5wvi7nf q3lfd5jv pk4s997a bipmatt0 cebpdrjk qowsmv63 owwhemhu dp1hu0rb dhp61c6y iyyx5f41']/div[@class='bp9cbjyn j83agx80 byvelhso l9j0dhe7']/a[@class='oajrlxb2 g5ia77u1 qu0x051f esr5mh6w e9989ue4 r7d6kgcz rq0escxv nhd2j8a9 j83agx80 p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso i1ao9s8h esuyzwwr f1sip0of lzcic4wl l9j0dhe7 abiwlrkh p8dawk7l bp9cbjyn cbu4d94t datstx6m taijpn5t k4urcfbm']").click()
time.sleep(random.random()*10+3)
browser.find_element_by_xpath("//div[@class='j83agx80 cbu4d94t buofh1pr l9j0dhe7']/div[6]/a[@class='oajrlxb2 gs1a9yip g5ia77u1 mtkw9kbi tlpljxtp qensuy8j ppp5ayq2 goun2846 ccm00jje s44p3ltw mk2mc5f4 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv nhd2j8a9 a8c37x1j mg4g778l btwxx1t3 pfnyh3mw p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x tgvbjcpo hpfvmrgz jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso l9j0dhe7 i1ao9s8h esuyzwwr f1sip0of du4w35lb lzcic4wl abiwlrkh p8dawk7l ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 nnctdnn4 hpfvmrgz qt6c0cv9 jb3vyjys l9j0dhe7 du4w35lb bp9cbjyn btwxx1t3 dflh9lhu scb9dxdr']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz qt6c0cv9 rz4wbd8a a8nywdso jb3vyjys du4w35lb bp9cbjyn btwxx1t3 l9j0dhe7']/div[@class='gs1a9yip ow4ym5g4 auili1gw rq0escxv j83agx80 cbu4d94t buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz rz4wbd8a a8nywdso l9j0dhe7 du4w35lb rj1gh0hx pybr56ya f10w8fjw']/div/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d'][1]/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db a5q79mjw g1cxx5fr ekzkrbhg oo9gr5id hzawbc8m']/span[@class='a8c37x1j ni8dbmo4 stjgntxs l9j0dhe7 ojkyduve']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh jq4qci2q a3bd9o3v lrazzd5p oo9gr5id']").click()
time.sleep(random.random()*10+3)
browser.find_element_by_xpath("//div[@class='soycq5t1 l9j0dhe7']/div[@class='i09qtzwb rq0escxv n7fi1qx3 pmk7jnqg j9ispegn kr520xx4']/a[@class='oajrlxb2 g5ia77u1 qu0x051f esr5mh6w e9989ue4 r7d6kgcz rq0escxv nhd2j8a9 pq6dq46d p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso i1ao9s8h esuyzwwr f1sip0of lzcic4wl l9j0dhe7 abiwlrkh p8dawk7l dwo3fsh8 ow4ym5g4 auili1gw mf7ej076 gmql0nx0 tkr6xdv7 bzsjyuwj cb02d2ww j1lvzwm4'][4]/div[@class='bp9cbjyn rq0escxv j83agx80 pfnyh3mw frgo5egb l9j0dhe7 cb02d2ww hv4rvrfc dati1w0a']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v lrazzd5p m9osqain']").click()
time.sleep(random.random()*10+3)
# browser.find_element_by_xpath("//div[@class='aov4n071']/div[@class='r54jmrld']/div[11]/a[@class='oajrlxb2 gs1a9yip g5ia77u1 mtkw9kbi tlpljxtp qensuy8j ppp5ayq2 goun2846 ccm00jje s44p3ltw mk2mc5f4 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv nhd2j8a9 a8c37x1j mg4g778l btwxx1t3 pfnyh3mw p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x tgvbjcpo hpfvmrgz jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso l9j0dhe7 i1ao9s8h esuyzwwr f1sip0of du4w35lb lzcic4wl abiwlrkh p8dawk7l ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 nnctdnn4 hpfvmrgz qt6c0cv9 jb3vyjys l9j0dhe7 du4w35lb bp9cbjyn btwxx1t3 dflh9lhu scb9dxdr']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz qt6c0cv9 rz4wbd8a a8nywdso jb3vyjys du4w35lb bp9cbjyn btwxx1t3 l9j0dhe7']/div[@class='gs1a9yip ow4ym5g4 auili1gw rq0escxv j83agx80 cbu4d94t buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz rz4wbd8a a8nywdso l9j0dhe7 du4w35lb rj1gh0hx pybr56ya f10w8fjw']/div/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb mdeji52x a5q79mjw g1cxx5fr ekzkrbhg oo9gr5id hzawbc8m']").click()
# time.sleep(random.random()*10+3)

n = 1000
m = 0
while m < 1500:
    browser.execute_script(f"window.scrollTo(0,{n})")
    m += 10
    print(m, '*************************************', n)
    n += 3000
    time.sleep(5)
# link_list = browser.find_elements_by_xpath("//div[@class='ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi a8c37x1j']")
# link_list = link_list[5:]
# listlie = []
# k = 1
#
# for i in link_list:
#     try:
#     # 本人名字链接
#         lianjie = i.find_element_by_xpath(
#             ".//div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v ekzkrbhg oo9gr5id hzawbc8m']/span/div[@class='nc684nl6']/a").get_attribute(
#             'href')
#     except Exception as ii:
#         lianjie='/'
#     print('lianjie',lianjie)
#     listlie.append(lianjie)
# for j in listlie:
#     jimm = 'p'
#     tao='i'
#     k += 1
#     time.sleep(2)
#     if j=='/':
#         ws.cell(row=k, column=6).value = '/'
#         ws.cell(row=k, column=7).value = '/'
#         ws.cell(row=k, column=8).value = '/'
#         ws.cell(row=k, column=9).value = '/'
#         ws.cell(row=k, column=10).value = '/'
#         ws.cell(row=k, column=11).value = '/'
#         print('00000000000000000000000000000000000')
#     else:
#         browser.get(f"{j}")
#         time.sleep(6)
#         ws.cell(row=1, column=1).value = f'nname'
#         ws.cell(row=1, column=2).value = f'lianjie'
#         ws.cell(row=1, column=3).value = f'jieshaorenname'
#         ws.cell(row=1, column=4).value = f'jieshaorenlianjie'
#         ws.cell(row=1, column=5).value = f'shijian'
#
#
#         ws.cell(row=1, column=6).value = 'Career'
#         ws.cell(row=1, column=7).value = 'Location'
#         ws.cell(row=1, column=8).value = 'Married'
#         ws.cell(row=1, column=9).value = 'Website'
#         ws.cell(row=1, column=10).value = 'School'
#         ws.cell(row=1, column=11).value = 'Home'
#
#         ws.cell(row=k, column=1).value = f'/'
#         ws.cell(row=k, column=2).value = f'/'
#         ws.cell(row=k, column=3).value = f'/'
#         ws.cell(row=k, column=4).value = f'/'
#         ws.cell(row=k, column=5).value = f'/'
#
#         ws.cell(row=k, column=6).value = '/'
#         ws.cell(row=k, column=7).value = '/'
#         ws.cell(row=k, column=8).value = '/'
#         ws.cell(row=k, column=9).value = '/'
#         ws.cell(row=k, column=10).value = '/'
#         ws.cell(row=k, column=11).value = '/'
#
#         try:
#             # 点击头像
#             browser.find_element_by_xpath(
#                 "//a[@class='oajrlxb2 gs1a9yip g5ia77u1 mtkw9kbi tlpljxtp qensuy8j ppp5ayq2 goun2846 ccm00jje s44p3ltw mk2mc5f4 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv nhd2j8a9 q9uorilb mg4g778l btwxx1t3 pfnyh3mw p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x tgvbjcpo hpfvmrgz jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso l9j0dhe7 i1ao9s8h esuyzwwr f1sip0of du4w35lb lzcic4wl abiwlrkh p8dawk7l oo9gr5id']").click()
#             time.sleep(int(random.random() * 10)+3)
#         except Exception as jj:
#             ws.cell(row=k, column=6).value = '///'
#             ws.cell(row=k, column=7).value = '///'
#             ws.cell(row=k, column=8).value = '///'
#             ws.cell(row=k, column=9).value = '///'
#             ws.cell(row=k, column=10).value = '///'
#             ws.cell(row=k, column=11).value = '///'
#             browser.back()
#             time.sleep(int(random.random() * 10)+1)
#             jimm='jim'
#
#         if jimm!='jim':
#             try:
#                 # 点击本人名字
#                 browser.find_element_by_xpath(
#                     "//div[@class='aahdfvyu']/h2[@class='gmql0nx0 l94mrbxd p1ri9a11 lzcic4wl aahdfvyu']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh jq4qci2q a3bd9o3v knj5qynh m9osqain']/div[@class='nc684nl6']/a[@class='oajrlxb2 g5ia77u1 qu0x051f esr5mh6w e9989ue4 r7d6kgcz rq0escxv nhd2j8a9 nc684nl6 p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso i1ao9s8h esuyzwwr f1sip0of lzcic4wl oo9gr5id gpro0wi8 lrazzd5p']").click()
#             except Exception as  jj:
#                 browser.back()
#                 time.sleep(int(random.random() * 10) + 1)
#                 browser.back()
#                 time.sleep(int(random.random() * 10) + 1)
#                 print('本人名字无连接')
#                 tao='tao'
#             if tao!='tao':
#                 # 获取全部信息
#                 try:
#                     time.sleep(int(random.random() * 10)+3)
#                     jim = browser.find_elements_by_xpath(
#                         "//ul/div['@class=rq0escxv l9j0dhe7 du4w35lb j83agx80 pfnyh3mw jifvfom9 gs1a9yip owycx6da btwxx1t3 jb3vyjys b5q2rw42 lq239pai mysgfdmx hddg9phg']")
#                     # print(jim,'000000000000000000000000000000')
#
#                     for bian in jim:
#                         # print(bian.text)
#                         jim01 = bian.find_element_by_xpath(
#                             ".//div[@class='rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t pfnyh3mw d2edcug0 hpfvmrgz p8fzw8mz pcp91wgn iuny7tx3 ipjc6fyt']/img[@class='hu5pjgll cwsop09l']").get_attribute(
#                             'src')
#                         # print(jim01,'----------------------------------------')
#                         jim01 = str(jim01)
#                         if jim01 == 'https://static.xx.fbcdn.net/rsrc.php/v3/yk/r/M0Wls5DHC-A.png':
#                             Career = bian.find_element_by_xpath(
#                                 ".//div[@class='rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t g5gj957u d2edcug0 hpfvmrgz rj1gh0hx buofh1pr o8rfisnq p8fzw8mz pcp91wgn iuny7tx3 ipjc6fyt']/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v knj5qynh oo9gr5id hzawbc8m']").text
#
#                             ws.cell(row=k, column=6).value = f'{Career}'
#                             print(Career)
#                         elif jim01 == 'https://static.xx.fbcdn.net/rsrc.php/v3/ym/r/N_tq7yNW9DG.png':
#                             Location = bian.find_element_by_xpath(
#                                 ".//div[@class='rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t g5gj957u d2edcug0 hpfvmrgz rj1gh0hx buofh1pr o8rfisnq p8fzw8mz pcp91wgn iuny7tx3 ipjc6fyt']/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v knj5qynh oo9gr5id hzawbc8m']").text
#                             ws.cell(row=k, column=7).value = f'{Location}'
#                             print(Location)
#
#                         elif jim01 == 'https://static.xx.fbcdn.net/rsrc.php/v3/yq/r/S0aTxIHuoYO.png':
#                             Married = bian.find_element_by_xpath(
#                                 ".//div[@class='rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t g5gj957u d2edcug0 hpfvmrgz rj1gh0hx buofh1pr o8rfisnq p8fzw8mz pcp91wgn iuny7tx3 ipjc6fyt']/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v knj5qynh oo9gr5id hzawbc8m']").text
#                             ws.cell(row=k, column=8).value = f'{Married}'
#                             print(Married)
#                         elif jim01 == 'https://static.xx.fbcdn.net/rsrc.php/v3/yw/r/zvm_GlT6_y2.png':
#                             Website = bian.find_element_by_xpath(
#                                 ".//div[@class='rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t g5gj957u d2edcug0 hpfvmrgz rj1gh0hx buofh1pr o8rfisnq p8fzw8mz pcp91wgn iuny7tx3 ipjc6fyt']/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v knj5qynh oo9gr5id hzawbc8m']").text
#                             ws.cell(row=k, column=9).value = f'{Website}'
#                             print(Website)
#                         elif jim01 == 'https://static.xx.fbcdn.net/rsrc.php/v3/yd/r/id4jdGYPaIP.png':
#                             School1 = bian.find_element_by_xpath(
#                                 ".//div[@class='rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t g5gj957u d2edcug0 hpfvmrgz rj1gh0hx buofh1pr o8rfisnq p8fzw8mz pcp91wgn iuny7tx3 ipjc6fyt']/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v knj5qynh oo9gr5id hzawbc8m']").text
#                             ws.cell(row=k, column=10).value = f'{School1}'
#                             print(School1)
#
#                         elif jim01 == 'https://static.xx.fbcdn.net/rsrc.php/v3/yk/r/X_t0JnueVu-.png':
#                             Home = bian.find_element_by_xpath(
#                                 ".//div[@class='rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t g5gj957u d2edcug0 hpfvmrgz rj1gh0hx buofh1pr o8rfisnq p8fzw8mz pcp91wgn iuny7tx3 ipjc6fyt']/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v knj5qynh oo9gr5id hzawbc8m']").text
#                             ws.cell(row=k, column=11).value = f'{Home}'
#                             print(Home)
#
#                         print('\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
#                     time.sleep(int(random.random() * 10)+1)
#                     browser.back()
#                     time.sleep(int(random.random() * 10)+1)
#                     browser.back()
#                     time.sleep(int(random.random() * 10)+1)
#                     browser.back()
#                     time.sleep(int(random.random() * 10)+1)
#                 except Exception as jj:
#                     print('/////////////////////')
#                     browser.back()
#                     time.sleep(int(random.random() * 10)+1)
#                     browser.back()
#                     time.sleep(int(random.random() * 10)+1)
#                     browser.back()
#                     time.sleep(int(random.random() * 10) + 1)
#
#
#
#
#
#
#
#
# print('-----------------------------------------------------------------------------------------')
#
# time.sleep(int(random.random()*10))
#
# wb.save('FaceBook6.xlsx')
# print('保存成功')











